/**
 * 用户账户管理初始化
 */
var Account = {
    id: "AccountTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Account.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '序号', field: 'id', visible: true, align: 'center', valign: 'middle',
                formatter: function (value, row, index) {
                    return index+1;
                }},
            {title: '用户手机号', field: 'userPhone', visible: true, align: 'center', valign: 'middle'},
            {title: '用户名', field: 'userName', visible: true, align: 'center', valign: 'middle'},
            {title: '现金余额', field: 'cash', visible: true, align: 'center', valign: 'middle'},
            {title: '现金转换的HHTB', field: 'hhtbc', visible: true, align: 'center', valign: 'middle'},
            {title: '交易所复投的HHTB', field: 'hhtbe', visible: true, align: 'center', valign: 'middle'},
            {title: '猫币定期', field: 'statedcc', visible: true, align: 'center', valign: 'middle'},
            {title: '猫币余额', field: 'blancecc', visible: true, align: 'center', valign: 'middle'},
            {title: '商城可消费余额', field: 'mailcc', visible: true, align: 'center', valign: 'middle'},
            {title: '理财余额', field: 'moneycc', visible: true, align: 'center', valign: 'middle'},
            {title: '账户定期状态', field: 'status', visible: true, align: 'center', valign: 'middle',
                formatter:Account.status},
            {title: '理财账户产生利息状态 0不允许 1允许', field: 'financialStutas', visible: true, align: 'center', valign: 'middle',
                formatter:Account.financialStutas}
    ];
};

//账户定期状态 0锁定 1开启
Account.status= function(value){
    var result = '';
    if(value == 0){
        result = '锁定';
    }else if(value == 1){
        result = '开启';
    }
    return result;
}
//理财账户产生利息状态 0不允许 1允许
Account.financialStutas= function(value){
    var result = '';
    if(value == 0){
        result = '锁定';
    }else if(value == 1){
        result = '开启';
    }
    return result;
}
/**
 * 检查是否选中
 */
Account.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Account.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加用户账户
 */
Account.openAddAccount = function () {
    var index = layer.open({
        type: 2,
        title: '添加用户账户',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/account/account_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看用户账户详情
 */
Account.openAccountDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '用户账户详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/account/account_update/' + Account.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除用户账户
 */
Account.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/account/delete", function (data) {
            Feng.success("删除成功!");
            Account.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("accountId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询用户账户列表
 */
Account.search = function () {
    var queryData = {};
    queryData['userPhone'] = $("#userPhone").val();
    queryData['userName'] = $("#userName").val();
    Account.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Account.initColumn();
    var table = new BSTable(Account.id, "/account/list", defaultColunms);
    table.setPaginationType("server");
    Account.table = table.init();
});
